import javax.imageio.IIOException;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        File f = new File("test.txt");
        BufferedWriter bufferedWriter = null;
        try {
            Writer writer = new FileWriter(f);
            bufferedWriter = new BufferedWriter(writer);
        }catch (IOException e){
            e.printStackTrace();
        }
        if (!f.isFile()){
            try {
                f.createNewFile();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        if (f.canWrite()){
            for (int i = 1;i<=100;i++){
                String line = "这是第" + i +"行";
                if (bufferedWriter !=null){
                    try {
                        bufferedWriter.write(line);
                        bufferedWriter.newLine();
                    }catch (IOException e){
                        e.printStackTrace();
                    }

                }

            }
            try {
                bufferedWriter.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}